Original address: Http://www.seleniumhq.org/docs/03_webdriver.jsp#selenium-webdriver-api-commands-and-operations
(This article is only for the Python part of the translation)
First of all, I have a point: my English is very poor, so this translation is only used to understand more deeply the use of webdriver.
First, ge
element be positioned when calledPerform ()Perform all the stored behavior in the Actionchains, which can be interpreted as a commit action for the entire operation3.2 Mouse Hover move_to_element ()The Move_to_element () method simulates a mouse hover action with the same usage as Context_click ()Dive = driver.find_element_by_css_selector (' #a ')Actionchains (Driver). Move_to_element (Dive). Perform ()Double_click() Drag_and_drop (Source,target)Source mouse Drag from elementTarget mouse-releas
1.1 Download Selenium2.0 's Package
Official download package Address: Http://code.google.com/p/selenium/downloads/list
Official User guide:http://seleniumhq.org/docs/
Official api:http://selenium.googlecode.com/git/docs/api/java/index.html
1.2.1 Open a browser with Webdriver
Open Firefox
Nosuchelementexception, E:# Capturing Nosuchelementexception ExceptionsPrint Traceback.print_exc ()Except Exception, E:# Catch Other exceptionsPrint Traceback.print_exc ()Else# Find the Date Input box page element on the tested pageDateinputbox = self.driver.find_element_by_id ("DatePicker")# Find the Date input box and enter the date string in the specified format directly# You can make a selection on a date control in a disguised simulation# Dateinputbox.send_keys ("11/24/2016") #直接输入的方式,Date
() Get CSS property values high 22px width 500px print (u "search box height:", element.value_of_css_property ("height")) Print (U "search box width:", Element.value_of_css_property ("width")) #获取字体, the font is Arialziti = Element.value_of_css_property (" Font-family ") Print (U" search box font is: ", Ziti) #unittest断言assertEqual (Ziti," Arial ")
7. Clear the contents of the entryDriver = Webdriver. Firefox (executable_path= "D:\\geckodriver"
")# Enter Message bodyEditbox.send_keys (U "message body content")# switch out of the rich text box and go back to the default pageSelf.driver.switch_to.default_content ()# Find the "Send" button on the page and click on itSelf.driver.find_element_by_xpath ('//span[.= ' sent "]"). Click ()# Display is waiting for page elements containing the keyword "send success" to appear on the pageWait.until (ec.visibility_of_element_located\((By.xpath, '//span[.= "send Success"]))Print u "Mail sent successf
Content reference to: Official API documentation, download link: http://download.csdn.net/detail/kwgkwg001/4004500Bug Master: "SELENIUM2 Automation Test Practice-based on Python language"First, the principle of webdriver1, about WebdriverDesign mode: According to the classic design mode of server-client design;Server side: Remote server, which can be any browser, when the script launches the browser, the browser is remote server, its role is to wait f
API Reference:Https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocolhttps://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/webdriver-commands/Https://whitewaterhill.com/php-webdriver-bindings-0.9.0/status.htmlThis article attempts to simulate the implementation of the Webdriver Java binding d
methods on the keyboard, Send_keys () does not have the ability to simulate keyboard input, and can also be used to enter keys on the keyboard, even key combinations, such as the following example:# Simulate keyboard eventsFrom selenium import Webdriver# Introducing the Keys moduleFrom Selenium.webdriver.common.keys import keysDriver = Webdriver.chrome ("Installation Tool \python\chromedriver.exe")Driver.get ("http://www.baidu.com")# Input Box input
In the process of automated testing, by the network, testing equipment and many other factors, we often need to add some delay in the automated test script to better locate elements to do a series of operations.There are generally several ways to do this:1.implicitlyWait. Time-out when the object is recognized. After this time, if the object hasn't been found, it throws a Nosuchelement exception.2.setScriptTimeout. The time-out period for the asynchronous script.
(firefox_binary=binary) Driver.get ('http://www.baidu.com')#iframe Toggle ID or name, otherwise use XPath to locateDriver.switch_to.frame ("if")#back to previous pageDriver.switch_to.parent_frame ()#Multi-Window switching#get the current window handleSearch_windows=Driver.current_window_handledriver.find_element_by_link_text ('Login'). Click () driver.find_element_by_link_text ('Register Now'). Click ()#gets all the currently open window handlesAll_handles =Driver.window_handles#go to registrat
;"); - - //can be partially matched using the Java String API method -Assert.asserttrue (Messagetext.contains ("Job search"))); -Assert.asserttrue (Messagetext.startswith ("View short rent")); -Assert.asserttrue (Messagetext.endswith (">>")); in - //Close Driver to driver.quit (); + } -}code Example2. Get element attribute valuesThe GetAttribute () of the Webelement class returns the attribute value of the element
WebDriver API: Simple Element Operation Method Introduction, webdriverapi
After locating an element, You need to operate it, or click (button) or enter (input box );The most common WebDriver methods are as follows:(1) clear () the content in the text input box
The clear () method is used to clear the content in the text input box. For example, in the logon box,
= driver.find_element_by_name ("cheese")OrFrom selenium.webdriver.common.by Import byCheese = driver.find_element (by.name, "cheese")by Link TextAn example of how to find an element such as the following:Cheese = Driver.find_element_by_link_text ("cheese")OrFrom selenium.webdriver.common.by Import byCheese = driver.find_element (by.link_text, "cheese")by Partial Link TextAn example of how to find an element such as the following:Cheese = Driver.find_element_by_partial_link_text ("cheese")OrFrom
In Firefox version 33, python2.7 run Selenium webdriver API error:SessionNotCreatedException:Message:Unable to find a matching set of capabilitiesOnline search, said can upgrade browser version to more than 52, I upgraded to 55 version, no errorWorkaround:update Firefox to version >= 52.0.3, updating Firefox version 52.0.3 or more may also be related to the Geckodriver version, no specific verificationpyth
Content reference "Insect Master" books, interested in browse the Bookworm blog: https://home.cnblogs.com/u/fnng/ Basic element positioning
ID Locator
Name Locator
Class positioning
Tag positioning
Link positioning
Partial linkd positioning
XPath positioning
CSS Positioning
By location
ID Locator
The HTML rule id attribute must be unique in the HTML document and is very unique, and webdriver
speed is faster than XPath, and positioning success rate of 99%Authentication method: In the browser console, enter:$ (") Example: Enter $ ('. BG s_btn ') to verify that the element is positioned toPositioning strategy:(1) using the class attribute to locate:Find_element_by_css_selector (". BG s_btn")(2) Location by id attribute:Find_element_by_css_selector ("#kw")(3) Positioning by any attribute:Find_element_by_css_selector ("[autocomplete= ' off ']")(4) Combination positioning:Find_element_by
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.